import { baseURL } from "./env";
import axios from "axios";

const service = axios.create({
  baseURL: baseURL, // api 的 base_url,
  timeout: 5000, // 请求超时时间
});

// request拦截器
service.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    console.log(error); // for debug
    return Promise.reject(error);
  }
);
// response 拦截器
service.interceptors.response.use(
  response => {
    if(response.status === 200){
      return response.data;
    }else{
      Promise.reject();
    }
  },
  error => {
    console.log("err" + error); // for debug
    return Promise.reject();
  }
);

export default service;